package com.bysj.yqsht.web.controller;

import com.bysj.yqsht.bean.Account;
import com.bysj.yqsht.bean.extend.AccountExtend;
import com.bysj.yqsht.service.IAccountService;
import com.bysj.yqsht.utils.Message;
import com.bysj.yqsht.utils.MessageUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/account")
@Api(description = "账号管理接口")
public class AccountController {
    @Autowired
    private IAccountService accountService;

    @GetMapping("findAll")
    public Message findAll(){
        List<Account> accounts = accountService.findAll();
        return MessageUtil.success(accounts);
    }
    @GetMapping("findWithAll")
    public Message findWithAll(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int limit){
        List<AccountExtend> accountExtends = accountService.findWithAll(pageNum,limit);
        return MessageUtil.success(accountExtends);
    }
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Account account){
        accountService.saveOrUpdate(account);
        return MessageUtil.success("新增或修改成功");
    }
    @GetMapping("deleteById")
    public Message deleteById(long id){
        accountService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
    @GetMapping("findWithAllBy")
    public Message findWithAllBy(Long roleId,String name){
        List<AccountExtend> extendList = accountService.findWithAllBy(roleId,name);
        return MessageUtil.success(extendList);

    }
}
